/* eslint-disable */
import audioSetup from "@/utils/aboutArticle/audio"; 
// 重置页面样式
function resetElement() {
  var $tag = $(".adw-content *");
  $tag.each(function () {
    if ($(this).css("background-image").indexOf("https://mmbiz.qpic.cn") > -1) {
      $(this).css("background-image", "");
    }
    if ($(this).css("background").indexOf("https://mmbiz.qpic.cn") > -1) {
      $(this).css("background", "");
    }
    if ($(this).width() > $(".adw-content").width()) {
      console.log($(this).width())
      $(this).css({
        "max-width": "100%"
      })
    }
    if (parseFloat($(this).css("max-width").split("px")[0]) > $(".adw-content").width()) {
      $(this).css({
        "max-width": "100%"
      })
    }
    if ($(this).width() > $(".adw-content").width()) {
      $(this).css({
        "width": $(".adw-content").width() + "px"
      })
    }
  });
  var $tagImg = $(".adw-content img");
  $tagImg.each(function () {
    var _this = this;
    if ($(_this).attr("data-src")) {
      $(_this).attr("src", $(_this).attr("data-src"));
    }

  });
  $tagImg.each(function () {
    var _this = this;
    $(_this).load(function () {
      if ($(_this).width() >= ($(".adw-content").width() * 0.8)) {
        console.log($(_this).css("display"));
        if ($(_this).css("display") !== "none") {
          $(_this).css({
            "width": $(".adw-content").width() + "px",
            "height": "auto",
            "display": "block"
          });
          $(_this).css("width", "100%")
        }
        $(_this).attr("width", $(".adw-content").width() + "");
      } else if ($(_this).width() >= ($(".adw-content").width() / 3)) {

      }
    });
  });
  var $audioMP = $(".audio-sectionmp");
  var $audioQQ = $(".audio-section");
  if ($audioMP.length > 0) {
    $audioMP.each(function (index) {
      audioSetup.install();
    })
  }
  if ($audioQQ.length > 0) {
    $audioQQ.each(function (index) {
      audioSetup.install();
    })
  }
  var $mpvoice = $("mpvoice");
  console.log($mpvoice.length )
  if ($mpvoice.length > 0) {
    $mpvoice.each(function (index) {
      if (index <= 20) {
        var voiceTitle;
        if (!checkStringIsNull($(this).attr("name"))) {
          voiceTitle = $(this).attr("name");
        } else if (!checkStringIsNull($(this).attr("data-name"))) {
          voiceTitle = $(this).attr("data-name");
        } else {
          voiceTitle = ("未知歌曲");
        }
        var voiceFileId;
        if (!checkStringIsNull($(this).attr("voice_encode_fileid"))) {
          voiceFileId = $(this).attr("voice_encode_fileid")
        } else if (!checkStringIsNull($(this).attr("data-voice_encode_fileid"))) {
          voiceFileId = $(this).attr("data-voice_encode_fileid")
        }
        console.log($(this).prop("outerHTML"));
        console.log($(this).attr("data-name"));
        var audioHtml = '<div id="js-audio-sectionmp' + index + '" class="audio-sectionmp">' +
          '<div id="js-audio-buttonmp' + index + '" class="audio-button">' +
          '<div id="js-playmp' + index + '" class="play" style="width:40px;height:40px;">' +
          '<span class="iconfont icon-pcduanbizhixiazaicishutubiao"></span>' +
          '</div>' +
          '<div id="js-pausemp' + index + '" class="pause" style="width:40px;height:40px;">' +
          '<span class="iconfont icon-yinlezanting"></span>' +
          '</div>' +
          '</div>' +
          '<span id="js-audio-namemp' + index + '" class="audio-name">' + voiceTitle + '</span>' +
          '<span id="js-audio-durationmp' + index + '" class="audio-duration"></span>' +
          '<audio id="js-audiomp' + index + '" data-source="https://res.wx.qq.com/voice/getvoice?mediaid=' + voiceFileId + '"  data-name="' + voiceTitle + '">' +
          '<source src="https://res.wx.qq.com/voice/getvoice?mediaid=' + voiceFileId + '" type="audio/mpeg">' +
          '<source src="https://res.wx.qq.com/voice/getvoice?mediaid=' + voiceFileId + '" type="auido/mp3">' +
          '</audio>' +
          '</div>';
        $(this).parent().html(audioHtml);
        audioSetup.install();
      }

    });
  }

  var $qqmusic = $("qqmusic");
  var qqmusicArry = [];
  var midurlinfo = [];
  if ($qqmusic.length > 0) {
    $qqmusic.each(function (item) {
      qqmusicArry.push($(this).attr("mid"));
    });

    var data = {
      "req": {
        "module": "CDN.SrfCdnDispatchServer",
        "method": "GetCdnDispatch",
        "param": {
          "guid": "4680094450",
          "calltype": 0,
          "userip": ""
        }
      },
      "req_0": {
        "module": "vkey.GetVkeyServer",
        "method": "CgiGetVkey",
        "param": {
          "guid": "4680094450",
          "songmid": qqmusicArry,
          "songtype": [0],
          "uin": "",
          "loginflag": 1,
          "platform": "20"
        }
      },
      "comm": {
        "uin": '',
        "format": "json",
        "ct": 24,
        "cv": 0
      }
    }
    let urlqq = 'https://u.y.qq.com/cgi-bin/musicu.fcg?-=getplaysongvkey5750188977044803&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data=' + JSON.stringify(data);
    $.ajax({
      url: urlqq,
      type: "get",
      dataType: 'jsonp',
      scriptCharset: 'GBK',//解决中文乱码
      success: function (data) {
        //最新音乐数据
        data.req_0.data.midurlinfo.forEach((item, index) => {
          midurlinfo.push(item.purl)
        })
        $qqmusic.each(function (index) {
          if (index <= 20) {
            var music_name = checkStringIsNull($(this).attr('music_name')) ? '其他歌曲' : $(this).attr('music_name');
            var audioHtml_qq = '<div id="js-audio-section' + index + '" class="audio-section">' +
              '<div id="js-audio-button' + index + '" class="audio-button">' +
              '<div id="js-play' + index + '" class="play" style="width:40px;height:40px;">' +
              '<span class="iconfont icon-pcduanbizhixiazaicishutubiao"></span>' +
              '</div>' +
              '<div id="js-pause' + index + '" class="pause" style="width:40px;height:40px;">' +
              '<span class="iconfont icon-yinlezanting"></span>' +
              '</div>' +
              '</div>' +
              '<span id="js-audio-name' + index + '" class="audio-name">' + music_name + '</span>' +
              '<span id="js-audio-duration' + index + '" class="audio-duration"></span>' +
              '<audio id="js-audio' + index + '" data-source="http://dl.stream.qqmusic.qq.com/' + midurlinfo[index] + '"  data-name="' + music_name + '">' +
              '<source src="http://dl.stream.qqmusic.qq.com/' + midurlinfo[index] + '" type="audio/mpeg">' +
              '<source src="http://dl.stream.qqmusic.qq.com/' + midurlinfo[index] + '" type="auido/mp3">' +
              '</audio>' +
              '</div>';
            $(this).parent().html(audioHtml_qq);
            audioSetup.install();
          }
        });
      },
      error: function (e) {
        console.log(e);
      }
    });
  }
  // $("audio").each(function () {  
  //     $(this).pause();
  // })
  setTimeout(function () {
    if (document.getElementById('js-audiomp0')) {
      document.getElementById('js-audiomp0').pause();
    }
    if (document.getElementById('js-audiomp1')) {
      document.getElementById('js-audiomp1').pause();

    }
    if (document.getElementById('js-audiomp2')) {

      document.getElementById('js-audiomp2').pause();

    }
    if (document.getElementById('js-audiomp3')) {
      document.getElementById('js-audiomp3').pause();
    }
    if (document.getElementById('js-audiomp4')) {
      document.getElementById('js-audiomp4').pause();
    }
    if (document.getElementById('js-audiomp5')) {
      document.getElementById('js-audiomp5').pause();
    }
    if (document.getElementById('js-audiomp6')) {
      document.getElementById('js-audiomp6').pause();
    }
    if (document.getElementById('js-audiomp7')) {
      document.getElementById('js-audiomp7').pause();
    }
    if (document.getElementById('js-audiomp8')) {
      document.getElementById('js-audiomp8').pause();
    }
    if (document.getElementById('js-audiomp9')) {
      document.getElementById('js-audiomp9').pause();
    }
    if (document.getElementById('js-audiomp10')) {
      document.getElementById('js-audiomp10').pause();
    }
    if (document.getElementById('js-audiomp11')) {
      document.getElementById('js-audiomp11').pause();
    }
    if (document.getElementById('js-audiomp12')) {
      document.getElementById('js-audiomp12').pause();
    }
    if (document.getElementById('js-audiomp13')) {
      document.getElementById('js-audiomp13').pause();
    }
    if (document.getElementById('js-audiomp14')) {
      document.getElementById('js-audiomp14').pause();
    }
    if (document.getElementById('js-audiomp15')) {
      document.getElementById('js-audiomp15').pause();
    }
    if (document.getElementById('js-audiomp16')) {
      document.getElementById('js-audiomp16').pause();
    }
    if (document.getElementById('js-audiomp17')) {
      document.getElementById('js-audiomp17').pause();
    }
    if (document.getElementById('js-audiomp18')) {
      document.getElementById('js-audiomp18').pause();
    }
    if (document.getElementById('js-audiomp19')) {
      document.getElementById('js-audiomp19').pause();
    }
    if (document.getElementById('js-audiomp20')) {
      document.getElementById('js-audiomp20').pause();
    }
    if (document.getElementById('js-audio0')) {
      document.getElementById('js-audio0').pause();

    }
    if (document.getElementById('js-audio1')) {
      document.getElementById('js-audio1').pause();

    }
    if (document.getElementById('js-audio2')) {

      document.getElementById('js-audio2').pause();

    }
    if (document.getElementById('js-audio3')) {
      document.getElementById('js-audio3').pause();
    }
    if (document.getElementById('js-audio4')) {
      document.getElementById('js-audio4').pause();
    }
    if (document.getElementById('js-audio5')) {
      document.getElementById('js-audio5').pause();
    }
    if (document.getElementById('js-audio6')) {
      document.getElementById('js-audio6').pause();
    }
    if (document.getElementById('js-audio7')) {
      document.getElementById('js-audio7').pause();
    }
    if (document.getElementById('js-audio8')) {
      document.getElementById('js-audio8').pause();
    }
    if (document.getElementById('js-audio9')) {
      document.getElementById('js-audio9').pause();
    }
    if (document.getElementById('js-audio10')) {
      document.getElementById('js-audio10').pause();
    }
    if (document.getElementById('js-audio11')) {
      document.getElementById('js-audio11').pause();
    }
    if (document.getElementById('js-audio12')) {
      document.getElementById('js-audio12').pause();
    }
    if (document.getElementById('js-audio13')) {
      document.getElementById('js-audio13').pause();
    }
    if (document.getElementById('js-audio14')) {
      document.getElementById('js-audio14').pause();
    }
    if (document.getElementById('js-audio15')) {
      document.getElementById('js-audio15').pause();
    }
    if (document.getElementById('js-audio16')) {
      document.getElementById('js-audio16').pause();
    }
    if (document.getElementById('js-audio17')) {
      document.getElementById('js-audio17').pause();
    }
    if (document.getElementById('js-audio18')) {
      document.getElementById('js-audio18').pause();
    }
    if (document.getElementById('js-audio19')) {
      document.getElementById('js-audio19').pause();
    }
    if (document.getElementById('js-audio20')) {
      document.getElementById('js-audio20').pause();
    }
  }, 600)
  $(".articledetailwrap").trigger('create');
  $("#adwContentList").trigger('create');

}
/**
 * 是否爲空
 * @param {Object} str
 */
function checkStringIsNull(str)
{
	str = $.trim(str);
     if (str !=null && str !="null" && str !='' && str !="" && str !=" " && str !=undefined && str !="undefined")
    {
        return false;
     }else{
     	return true;
     }

}

export default {
  install(){
    resetElement()
  }
};